
/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2018原作者。
 *
 *根据Apache许可证2.0版（“许可证”）许可；
 *除非符合许可证的规定，否则您不得使用此文件。
 *您可以在以下网址获取许可证副本
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，否则软件
 *根据许可证分发是在“按原样”的基础上分发的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限的特定语言，请参阅许可证
 *许可证下的限制。
 */

package org.springframework.context.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.context.weaving.DefaultContextLoadTimeWeaver;
import org.springframework.instrument.classloading.LoadTimeWeaver;

/**
 * Activates a Spring {@link LoadTimeWeaver} for this application context, available as
 * a bean with the name "loadTimeWeaver", similar to the {@code <context:load-time-weaver>}
 * element in Spring XML.
 *
 * <p>To be used on @{@link org.springframework.context.annotation.Configuration Configuration} classes;
 * the simplest possible example of which follows:
 *
 * <pre class="code">
 * &#064;Configuration
 * &#064;EnableLoadTimeWeaving
 * public class AppConfig {
 *
 *     // application-specific &#064;Bean definitions ...
 * }</pre>
 *
 * The example above is equivalent to the following Spring XML configuration:
 *
 * <pre class="code">
 * &lt;beans&gt;
 *
 *     &lt;context:load-time-weaver/&gt;
 *
 *     &lt;!-- application-specific &lt;bean&gt; definitions --&gt;
 *
 * &lt;/beans&gt;
 * </pre>
 *
 * <h2>The {@code LoadTimeWeaverAware} interface</h2>
 * Any bean that implements the {@link
 * org.springframework.context.weaving.LoadTimeWeaverAware LoadTimeWeaverAware} interface
 * will then receive the {@code LoadTimeWeaver} reference automatically; for example,
 * Spring's JPA bootstrap support.
 *
 * <h2>Customizing the {@code LoadTimeWeaver}</h2>
 * The default weaver is determined automatically: see {@link DefaultContextLoadTimeWeaver}.
 *
 * <p>To customize the weaver used, the {@code @Configuration} class annotated with
 * {@code @EnableLoadTimeWeaving} may also implement the {@link LoadTimeWeavingConfigurer}
 * interface and return a custom {@code LoadTimeWeaver} instance through the
 * {@code #getLoadTimeWeaver} method:
 *
 * <pre class="code">
 * &#064;Configuration
 * &#064;EnableLoadTimeWeaving
 * public class AppConfig implements LoadTimeWeavingConfigurer {
 *
 *     &#064;Override
 *     public LoadTimeWeaver getLoadTimeWeaver() {
 *         MyLoadTimeWeaver ltw = new MyLoadTimeWeaver();
 *         ltw.addClassTransformer(myClassFileTransformer);
 *         // ...
 *         return ltw;
 *     }
 * }</pre>
 *
 * <p>The example above can be compared to the following Spring XML configuration:
 *
 * <pre class="code">
 * &lt;beans&gt;
 *
 *     &lt;context:load-time-weaver weaverClass="com.acme.MyLoadTimeWeaver"/&gt;
 *
 * &lt;/beans&gt;
 * </pre>
 *
 * <p>The code example differs from the XML example in that it actually instantiates the
 * {@code MyLoadTimeWeaver} type, meaning that it can also configure the instance, e.g.
 * calling the {@code #addClassTransformer} method. This demonstrates how the code-based
 * configuration approach is more flexible through direct programmatic access.
 *
 * <h2>Enabling AspectJ-based weaving</h2>
 * AspectJ load-time weaving may be enabled with the {@link #aspectjWeaving()}
 * attribute, which will cause the {@linkplain
 * org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter AspectJ class transformer} to
 * be registered through {@link LoadTimeWeaver#addTransformer}. AspectJ weaving will be
 * activated by default if a "META-INF/aop.xml" resource is present on the classpath.
 * Example:
 *
 * <pre class="code">
 * &#064;Configuration
 * &#064;EnableLoadTimeWeaving(aspectjWeaving=ENABLED)
 * public class AppConfig {
 * }</pre>
 *
 * <p>The example above can be compared to the following Spring XML configuration:
 *
 * <pre class="code">
 * &lt;beans&gt;
 *
 *     &lt;context:load-time-weaver aspectj-weaving="on"/&gt;
 *
 * &lt;/beans&gt;
 * </pre>
 *
 * <p>The two examples are equivalent with one significant exception: in the XML case,
 * the functionality of {@code <context:spring-configured>} is implicitly enabled when
 * {@code aspectj-weaving} is "on".  This does not occur when using
 * {@code @EnableLoadTimeWeaving(aspectjWeaving=ENABLED)}. Instead you must explicitly add
 * {@code @EnableSpringConfigured} (included in the {@code spring-aspects} module)
 *
 * @author Chris Beams
 * @since 3.1
 * @see LoadTimeWeaver
 * @see DefaultContextLoadTimeWeaver
 * @see org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter
 */
/**
 *为此应用程序上下文激活Spring｛@link LoadTimeWeaver｝，可用作
 *一个名为“loadTimeWeaver”的bean，类似于{@code＜context:load-timeweaver＞}
 *元素。
 *
 *<p>用于@{@link org.springframework.context.annotation.Configuration配置}类；
 *其最简单的可能示例如下：
 *
 *<pre-class=“code”>
 * &#064;配置
 * &#064;启用装载时间编织
 *公共类AppConfig{
 *
 *//特定于应用程序&#064；Bean定义。。。
 *}</pre>
 *
 *上面的示例等效于以下Spring XML配置：
 *
 *<pre-class=“code”>
 *&lt；豆类&gt；
 *
 *&lt；上下文：加载时间weaver/&gt；
 *
 *&lt；！——特定于应用程序&lt；豆&gt；定义--&gt；
 *
 *&lt/豆类&gt；
 *</pre>
 *
 *<h2>｛@code LoadTimeWeaverware｝接口</h2>
 *实现{@link的任何bean
 *org.springframework.context.weaving.LoadTimeWeaverware LoadTimeWeaverWare｝接口
 *然后将自动接收{@code LoadTimeWeaver}引用；例如
 *Spring的JPA引导程序支持。
 *
 *＜h2＞自定义｛@code LoadTimeWeaver｝</h2>
 *默认编织器是自动确定的：请参阅｛@link DefaultContextLoadTimeWeaver｝。
 *
 *＜p＞要自定义所使用的weaver，｛@code@Configuration｝类注释为
 *｛@code@EnableLoadTimeWiving｝也可以实现｛@link LoadTimeWeavingConfigurer｝
 *接口，并通过
 *｛@code#getLoadTimeWeaver｝方法：
 *
 *<pre-class=“code”>
 * &#064;配置
 * &#064;启用装载时间编织
 *公共类AppConfig实现LoadTimeWeavingConfigurer{
 *
 *     &#064;以（权力）否决
 *公共LoadTimeWeaver getLoadTimeWeafer（）{
 *MyLoadTimeWeaver ltw=新的MyLoadTimeWeaver（）；
 *ltw.addClassTransformer（myClassFileTransformer）；
 *         // ...
 *返回ltw；
 *     }
 *}</pre>
 *
 *<p>上面的示例可以与以下Spring XML配置进行比较：
 *
 *<pre-class=“code”>
 *&lt；豆类&gt；
 *
 *&lt；上下文：加载时间weaver-waverClass=“com.acme.MyLoadTimeWeaver”/&gt；
 *
 *&lt/豆类&gt；
 *</pre>
 *
 *＜p＞该代码示例与XML示例的不同之处在于，它实际上实例化了
 *｛@code MyLoadTimeWeaver｝类型，这意味着它也可以配置实例，例如。
 *调用{@code#addClassTransformer}方法。这展示了基于代码的
 *通过直接编程访问，配置方法更加灵活。
 *
 *<h2>启用基于AspectJ的编织</h2>
 *可以使用{@link#aspectjWeaving（）}启用AspectJ加载时编织
 *属性，这将导致｛@linkplain
 *org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter aspectj类转换器}到
 *通过{@link LoadTimeWeaver#addTransformer}注册。AspectJ编织将
 *如果类路径上存在“META-INF/aop.xml”资源，则默认情况下激活。
 *示例：
 *
 *<pre-class=“code”>
 * &#064;配置
 * &#064;EnableLoadTimeWeaving（aspectjWeaving=已启用）
 *公共类AppConfig{
 *}</pre>
 *
 *<p>上面的示例可以与以下Spring XML配置进行比较：
 *
 *<pre-class=“code”>
 *&lt；豆类&gt；
 *
 *&lt；上下文：加载时间weaver aspectj weaving=“on”/&gt；
 *
 *&lt/豆类&gt；
 *</pre>
 *
 *<p>这两个例子是等价的，但有一个重要的例外：在XML的情况下，
 *当
 *｛@code aspectj编织｝处于“打开”状态。使用时不会出现这种情况
 *｛@code@EnableLoadTimeWiving（aspectjWiving=ENABLED）｝。相反，您必须显式添加
 *｛@code@EnableSpringConfigured｝（包含在｛@code spring-aspects｝模块中）
 *
 *@作者Chris Beams
 *@自3.1起
 *@参见LoadTimeWeaver
 *@参见DefaultContextLoadTimeWeaver
 *@请参阅org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(LoadTimeWeavingConfiguration.class)
public @interface EnableLoadTimeWeaving {

	/**
	 * Whether AspectJ weaving should be enabled.
	 */
	/**
	 *是否应启用AspectJ编织。
	 */
	AspectJWeaving aspectjWeaving() default AspectJWeaving.AUTODETECT;


	/**
	 * AspectJ weaving enablement options.
	 */
	/**
	 *AspectJ编织启用选项。
	 */
	enum AspectJWeaving {

		/**
		 * Switches on Spring-based AspectJ load-time weaving.
		 */
		/**
		 *切换到基于Spring的AspectJ加载时编织。
		 */
		ENABLED,

		/**
		 * Switches off Spring-based AspectJ load-time weaving (even if a
		 * "META-INF/aop.xml" resource is present on the classpath).
		 */
		/**
		 *关闭基于Spring的AspectJ加载时编织（即使
		 *类路径上存在“META-INF/aop.xml”资源）。
		 */
		DISABLED,

		/**
		 * Switches on AspectJ load-time weaving if a "META-INF/aop.xml" resource
		 * is present in the classpath. If there is no such resource, then AspectJ
		 * load-time weaving will be switched off.
		 */
		/**
		 *如果有“META-INF/aop.xml”资源，则打开AspectJ加载时编织
		 *存在于类路径中。如果没有这样的资源，那么AspectJ
		 *装载时间编织将关闭。
		 */
		AUTODETECT;
	}

}
